<!--
 * @Author: ckk
 * @Date: 2022年7月19日14:41:30
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-08-25 14:53:35
 * @Description: 登录页面
 * @version: 1.0
-->
<template>
  <div class="login flexBox">
    <img src="@/assets/images/loading.gif" alt="" class="loading">
  </div>
</template>

<script>
import { getUrlParam } from '../../common/comfun';
import { authenticationServices } from '../../api';
import { getStudentCode } from '../../api/getContentApi';
import { Toast } from 'yj-mob-ui';
export default {
  data () {
    return {
      code: '',
      openInfo: {
        data: {}
      },
      show: true
    };
  },
  components: {
    [Toast.name]: Toast
  },
  async created () {
    this.loginIn();
    // this.loginIn1();
  },
  methods: {
    async loginIn () {
      if (getUrlParam('trustCodeTemp')) {
          const res2 = await authenticationServices.appUseAttestation({ trustCodeTemp: getUrlParam('trustCodeTemp') });
          if (res2) {
            localStorage.setItem('auth_token', JSON.stringify(res2));
            if (this.$route.query.productId) {
              localStorage.setItem('productId', this.$route.query.productId);
              localStorage.setItem('abutmentName', this.$route.query.abutmentName);
            }
            if (this.$route.query.productCode) {
              localStorage.setItem('productCode', this.$route.query.productCode);
            }
            const res1 = await getStudentCode();
            if (!res1.data.gradeCode) {
              this.$router.replace({ path: '/gradeChange' });
            } else {
              if (!res1.data.termCode) {
                res1.data.termCode = res1.data.currentTermCode;
              }
              localStorage.setItem('userInitInfo', JSON.stringify(res1.data));
              localStorage.setItem('gradeCode', res1.data.gradeCode);
              this.$router.push({ name: 'home' });
            }
          }
      }
    },
    async loginIn1 () {
      const res1 = await getStudentCode();
      if (!res1.data.gradeCode) {
        res1.data.gradeCode = res1.data.studentGradeCode;
      }
      if (!res1.data.termCode) {
        res1.data.termCode = res1.data.currentTermCode;
      }
      localStorage.setItem('userInitInfo', JSON.stringify(res1.data));
      localStorage.setItem('gradeCode', res1.data.gradeCode);
      if (this.$route.query.productId) {
        localStorage.setItem('productId', this.$route.query.productId);
        localStorage.setItem('abutmentName', this.$route.query.abutmentName);
      }
      if (this.$route.query.productCode) {
        localStorage.setItem('productCode', this.$route.query.productCode);
        this.$router.push({ name: 'home' });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.loading{
  width:80%;
  height: auto
}
.login{
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
